﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Diagnostics;
namespace Kamikaze
{
    class Menu : SceneBase
    {
        MouseState mouse, oldMouse;
        Texture2D texturaMenu;

        AnimatedObject botaoPlay;
        AnimatedObject botaoHistoria;
        AnimatedObject botaoCreditos;
        AnimatedObject botaoSair;
        Objeto2D logo;

        private Song song;
        private SoundEffect effect;

        public override void start()
        {
            Game1.Self.IsMouseVisible = true;

            Kamikaze.AnimatedObject.AnimationStructure animationMudarCor = new Kamikaze.AnimatedObject.AnimationStructure();
            animationMudarCor.frameCount = 1;
            animationMudarCor.frameWidth = 135;
            animationMudarCor.frameHeight = 36;
            animationMudarCor.framePerSecond = 1;
            animationMudarCor.X = 135;
            animationMudarCor.Y = 0;

            //Kamikaze.AnimatedObject.AnimationStructure animationMudarCor2 = new Kamikaze.AnimatedObject.AnimationStructure();
            //animationMudarCor2.frameCount = 1;
            //animationMudarCor2.frameWidth = 135;
            //animationMudarCor2.frameHeight = 37;
            //animationMudarCor2.framePerSecond = 1;
            //animationMudarCor2.X = 135;
            //animationMudarCor2.Y = 0;

            //Kamikaze.AnimatedObject.AnimationStructure animationMudarCor3 = new Kamikaze.AnimatedObject.AnimationStructure();
            //animationMudarCor3.frameCount = 1;
            //animationMudarCor3.frameWidth = 135;
            //animationMudarCor3.frameHeight = 37;
            //animationMudarCor3.framePerSecond = 1;
            //animationMudarCor3.X = 135;
            //animationMudarCor3.Y = 0;

            //Kamikaze.AnimatedObject.AnimationStructure animationMudarCor4 = new Kamikaze.AnimatedObject.AnimationStructure();
            //animationMudarCor4.frameCount = 1;
            //animationMudarCor2.frameWidth = 135;
            //animationMudarCor4.frameHeight = 37;
            //animationMudarCor4.framePerSecond = 1;
            //animationMudarCor4.X = 135;
            //animationMudarCor4.Y = 0;

            texturaMenu = (Game1.Self.Content.Load<Texture2D>(@"Imagens/fundoMenu"));

            botaoPlay = new AnimatedObject(Game1.Self.Content.Load<Texture2D>(@"Imagens/botao1"), 134, 36);
            botaoPlay.posicao.X = 300;
            botaoPlay.posicao.Y = 220;
            botaoPlay.listaAnimations.Add("mudarCor", animationMudarCor);

            botaoHistoria = new AnimatedObject(Game1.Self.Content.Load<Texture2D>(@"Imagens/botao2"), 134, 36);
            botaoHistoria.posicao.X = 300;
            botaoHistoria.posicao.Y = 270;
            botaoHistoria.listaAnimations.Add("mudarCor", animationMudarCor);

            botaoCreditos = new AnimatedObject(Game1.Self.Content.Load<Texture2D>(@"Imagens/botao3"), 134, 36);
            botaoCreditos.posicao.X = 300;
            botaoCreditos.posicao.Y = 320;
            botaoCreditos.listaAnimations.Add("mudarCor", animationMudarCor);

            botaoSair = new AnimatedObject(Game1.Self.Content.Load<Texture2D>(@"Imagens/botao4"), 134, 36);
            botaoSair.posicao.X = 300;
            botaoSair.posicao.Y = 370;
            botaoSair.listaAnimations.Add("mudarCor", animationMudarCor);


            logo = new Objeto2D(Game1.Self.Content.Load<Texture2D>(@"Imagens/logo"));
           logo.posicao.X = 0;
            logo.posicao.Y = 100;

            song = (Game1.Self.Content.Load<Song>(@"Sounds/DST-Alters"));
            effect = (Game1.Self.Content.Load<SoundEffect>(@"Sounds/button-20"));
          
            MediaPlayer.Play(song);
            MediaPlayer.IsRepeating = true;
            
            

        }

        public override void update(GameTime gameTime)
        {
            oldMouse = mouse;
            mouse = Mouse.GetState();

            if (logo.posicao.X <= 300)
            {
                logo.posicao.X += 4;
                botaoPlay.visible = false;
                botaoHistoria.visible = false;
                botaoCreditos.visible = false;
                botaoSair.visible = false;

            }

            else
            {
                botaoPlay.visible = true;
                botaoHistoria.visible = true;
                botaoCreditos.visible = true;
                botaoSair.visible = true;
            }




            botaoPlay.calcularRetangulo();
            botaoPlay.Update(gameTime);

            if (botaoPlay.collisionBounds.Contains(mouse.X, mouse.Y))
            {

                botaoPlay.ChangeAnimation("mudarCor");
            }
            else
            {

                botaoPlay.ChangeAnimation("default");
            }

            botaoHistoria.calcularRetangulo();
            botaoHistoria.Update(gameTime);


            if (botaoHistoria.collisionBounds.Contains(mouse.X, mouse.Y))
            {

                botaoHistoria.ChangeAnimation("mudarCor");
            }
            else
            {

                botaoHistoria.ChangeAnimation("default");
            }



            botaoCreditos.calcularRetangulo();
            botaoCreditos.Update(gameTime);


            if (botaoCreditos.collisionBounds.Contains(mouse.X, mouse.Y))
            {

                botaoCreditos.ChangeAnimation("mudarCor");
            }
            else
            {

                botaoCreditos.ChangeAnimation("default");
            }

            botaoSair.calcularRetangulo();
            botaoSair.Update(gameTime);


            if (botaoSair.collisionBounds.Contains(mouse.X, mouse.Y))
            {

                botaoSair.ChangeAnimation("mudarCor");
            }
            else
            {

                botaoSair.ChangeAnimation("default");
            }




           
            if (mouse.LeftButton == ButtonState.Pressed && oldMouse!=mouse)
            {
               
                if (botaoPlay.collisionBounds.Contains(mouse.X, mouse.Y))
                {
                    SceneManager.setScene(new Controles());
                    effect.Play();
                }


                if (botaoHistoria.collisionBounds.Contains(mouse.X, mouse.Y))
                {
                    SceneManager.setScene(new Historia());
                    effect.Play();
                }


                if (botaoCreditos.collisionBounds.Contains(mouse.X, mouse.Y))
                {
                    SceneManager.setScene(new Creditos());
                    effect.Play();
                }

                if (botaoSair.collisionBounds.Contains(mouse.X, mouse.Y))
                {
                    Process.GetCurrentProcess().Kill();
                }


                             
                

            }




            

        }

        public override void draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texturaMenu, new Vector2(0, 0), Color.White);
            botaoPlay.Draw(spriteBatch);
            botaoHistoria.Draw(spriteBatch);
            botaoCreditos.Draw(spriteBatch);
            botaoSair.Draw(spriteBatch);
            logo.Draw(spriteBatch);
            
        }

        public override void terminate()
        {
            Game1.Self.IsMouseVisible = false;
            MediaPlayer.Stop();

            
            
            
        }

    }
}
